function done = save_multipages(gvec, gname, save_path)
% done = save_multipage(gvec, gname, save_path)
% given a vector of graph handle (gvec), append all graphs into one file
% named gname, and then save it to save_path in either ps/pdf format.
%
% INPUT:
%     "GVEC":         vector of graph handle
%     "GNAME":        name of the file to be saved
%     "SAVE_PATH":    saving directory for the file
%
% OUTPUT:
%     "DONE":         If result file is created.
%
% RA: Xi Luo
% created 05/05/2010
%
done = 0;
cucd = pwd;
if nargin < 3;
    save_path = cucd; 
end 

if isempty(gvec);
    error('graph handle vector is empty');
elseif any(ishandle(gvec) == 0)
    error('gvec must be a vector of graph handles');
end

np = length(gvec);

if np == 1 && isunix == 0; 
    cd(save_path); 
    print(gvec(1), '-dpdf', gname);
    cd(cucd); 
    return
end 


    cd(save_path);
    print(gvec(1), '-dpsc', gname);
    if np > 1;
        for ii = 2:np
            print(gvec(ii), '-dpsc', '-append', gname);
        end
    end

    
    if isunix == 0
        try
            ps2pdf('psfile', [gname,'.ps'], 'pdffile', [gname, '.pdf'])
            delete([gname, '.ps'])
        catch
            display('Fail to convert PS to PDF '); 
            % display(); 
%             ps2pdf_new(gname, gname); 
%             delete([gname, '.ps'])
        end
    end
    cd(cucd);
    done = 1;


end